package class_17_03;


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Shirt implements Comparable {
    private int size;
    private String color;
    private String serial;

    public Shirt(int size, String color, String serial) {
        this.size = size;
        this.color = color;
        this.serial = serial;
    }
            
    @Override
    public boolean equals(Object object) {
        if(object instanceof Shirt) {
            //...Casting (forzar la instancia para que sea tipo fecha)
            Shirt shirt = (Shirt) object;
            return this.size == shirt.size && this.color.equals(shirt.getColor());
        }            
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 83 * hash + this.size;
        hash = 83 * hash + (this.color != null ? this.color.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        //return "El tamaño de la Camisa es :"+this.size +"\n"+ "El Color de la camisa es :"+this.color;
        return this.size + " " + this.color; 
    }

    public void setColor(String color) { this.color = color;}

    public void setSize(int size) { this.size = size; }

    public void setSerial(String serial) { this.serial = serial; }
        
    public String getColor() { return color; }

    public int getSize() { return size; }

    public String getSerial() { return serial; }

    @Override
    public int compareTo(Object object) {
        Shirt shirtToComparable = (Shirt)object;
        if(object instanceof Shirt) {
            //return size-shirtToComparable.getSize();
            return color.compareTo(shirtToComparable.getColor());
        }else{
            return size;
        }        
    }  
                
    public static void main(String[] args) {
         /*   
        Shirt shirt1 = new Shirt(48, "Azul"); Shirt shirt2 = new Shirt(48, "Azul");
        
        System.out.println(shirt1.hashCode() == shirt2.hashCode()); 
        System.out.println(shirt1.hashCode() != shirt2.hashCode());      
      
        SortedSet<Shirt> sortedSet = new TreeSet<Shirt>();
        sortedSet.add(new Shirt(3, "Red", "18772"));
        sortedSet.add(new Shirt(4, "Blue","18572"));
        
        for (Shirt toPrintSortedSet : sortedSet) {
            System.out.println(""+toPrintSortedSet.toString());
        }
          * 
          */
        
        Map<String, Shirt> mapStringShit = new HashMap<String, Shirt>();
        
        Shirt shirt1 = new Shirt(48, "Blue", "18572"); 
        Shirt shirt2 = new Shirt(45, "Maron", "1872");
        
        mapStringShit.put(shirt1.getSerial(), shirt1); 
        mapStringShit.put(shirt2.getSerial(), shirt2);
        /*
        System.out.println(""+mapStringShit.get("1872"));
        System.out.println(""+mapStringShit.entrySet());
         * 
         */
        
        Iterator it = mapStringShit.entrySet().iterator();

        while (it.hasNext()) {
            System.out.println(""+mapStringShit.toString());
            it.next();           
        }
 
    }
    
}
